﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Data.Sql;
using System.Data.SqlClient;
using System.Windows.Forms;
using Microsoft.SqlServer.Management.Smo;
using Microsoft.SqlServer.Management.Nmo;
using Microsoft.SqlServer.Management.Common;
using Microsoft.SqlServer.Management.Trace;
using Entity;

namespace DataControls
{
   public class CHUCVU_Data
    {
       DataBaseAccess dataBaseAccess = new DataBaseAccess();

       public void chucvu_Combobox(ComboBox cb)
       {
           String excuteString = "SELECT * FROM CHUCVU";
           dataBaseAccess.addto_Combobox(cb, excuteString);
       }

       public Boolean kiemtra_MaChucVu(String machucvu)
       {
           int i = 0;
           String excuteString = "SELECT COUNT(*) FROM CHUCVU WHERE MACV='" + machucvu + "'";
           i = dataBaseAccess.Test(excuteString);
           if (i == 0)
           {
               return false;
           }
           else
               return true;
       }

       public Boolean kiemtraMaCV_CVGV(String machucvu)
       {
           int i = 0;
           String excuteString = "SELECT COUNT(*) FROM CV_GIAOVIEN WHERE MACV='" + machucvu + "'";
           i = dataBaseAccess.Test(excuteString);
           if (i <= 0)
           {
               return false;
           }
           else
               return true;
       }

       public Boolean kiemtra_ChucVu(String tenchucvu)
       {
           int i = 0;
           String excuteString = "SELECT COUNT(*) FROM CHUCVU WHERE TENCV='" + tenchucvu + "'";
           i = dataBaseAccess.Test(excuteString);
           if (i == 0)
           {
               return false;
           }
           else
               return true;
       }

       public void layten_ChucVu(String machucvu,ComboBox cb)
       {
           int a= 0;
           String excuteString = "SELECT TENCV FROM CHUCVU WHERE MACV='" + machucvu + "'";
           String tenchucvu =dataBaseAccess.excuteReader(excuteString);
           for ( int i = 0; i < cb.Items.Count; i++ )
           {
               cb.SelectedIndex = i;
               if (cb.Text == tenchucvu)
                   a = i;
           }
           cb.SelectedIndex = a;
       }

       public void layten_GiaoVien(String magiaovien, ComboBox cb)
       {
           int a = 0;
           String excuteString = "SELECT TENGV FROM GIAOVIEN WHERE MAGV='" + magiaovien + "'";
           String tengiaovien = dataBaseAccess.excuteReader(excuteString);
           for ( int i = 0; i < cb.Items.Count; i++)
           {
               cb.SelectedIndex = i;
               if (tengiaovien.Equals(((ListItem)(cb.SelectedItem)).name))
                   a = i;        
           }
           cb.SelectedIndex = a;
       }











    }

}
